package cn.jbit.controller;

import cn.jbit.pojo.Order;
import cn.jbit.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 张在成
 */
@RestController
@Slf4j
public class RedisCacheController {

    @Autowired
    private OrderService orderService;

    @RequestMapping("/orderRemote/{orderId}")
    public Order getOrderDetailByOrderId(@PathVariable("orderId") Integer orderId){
        Order order=null;
        try {
            order=orderService.selectOrderByOrderId(orderId);
        }catch (Exception e){
            e.printStackTrace();
            log.info("rest根据主键id查询订单系统出现故障："+e.getMessage());
        }
        return order;
    }

    @RequestMapping("/orderListRemote/")
    public List<Order> getOrderList(){
        List<Order> orderList=null;
        try {
            Thread.sleep(2000);
            orderList=orderService.getOrderList();
        }catch (Exception e){
            e.printStackTrace();
            log.info("rest-order系统出现故障："+e.getMessage());
        }
        return orderList;
    }


    @RequestMapping(value = "/orderRemoteIds")
    public List<Order> getOrderList(@RequestBody List<Integer> list){
        List<Order> orderList=null;
        try {
            orderList=orderService.selOrderListByIds(list);
        }catch (Exception e){
            e.printStackTrace();
            log.info("rest根据多主主键查询系统出现故障："+e.getMessage());
        }
        return  orderList;
    }





}
